import { Component, OnInit } from '@angular/core'
import { JsonApiService } from 'app/core/api/json-api.service' //http请求配置引入
import { Router, ActivatedRoute } from '@angular/router' //路由引入
import { config } from '../../shared/smartadmin.config'

import 'script-loader!select2/dist/js/select2.min.js'
import 'assets/js/select2-zh-CN.js'

declare var $: any
declare var Viewer: any
@Component({
  selector: 'sa-device',
  templateUrl: './device.component.html',
  styleUrls: ['./device.css']
})
export class DeviceComponent implements OnInit {
  tableData: any[] = [] //table数据
  totalCount: number = 0 //分页总条数
  curPage: number = 1 //分页当前页
  pageSize: number = 10 //内置的分页每页条数
  searchKey: string = '' //搜索keyword
  btnData: any[] = []
  carAdd: boolean = false
  carEdit: boolean = false
  carDeleteBatch: boolean = false
  carStation: boolean = false
  carItinerary: boolean = false
  imgCheck: boolean = false
  modal: any = {
    //图片弹窗
    picture: '',
    carNumber: ''
  }
  selectedCompanyName: string = '' //公司名称
  selectedCompanyId: string = '' //公司ID
  useTypeL1: string = '' //useTypeL1  select值
  useTypeL2: string = '' //useTypeL2  select值
  sensorType: string = '' //传感器类型参数
  carTypeDetailList: any = [] //useTypeL2数据
  hwVersion: string = '' //硬件版本
  carTypeList = carTypeListObj.carTypeList
  carUseList = carTypeListObj.carUseList
  carDeatailUseList = carTypeListObj.carDeatailUseList
  startTime: string = ''
  endTime: string = ''
  isViewer: boolean = false //默认隐藏
  jumpData: any // 跳转页面接收到的数据
  carAttribution: any = '' //车辆归属
  userType: string = '' //用户类型
  userTypeList: any = [] // 用户类型列表

  payWay: any = '' // 缴费类型

  outsourcingTeamId: string = '' //实施团队
  outsourcingTeamName: string = '' //实施团队名称
  inputApi: any = 'user/teamTree.html'
  isShowRoot: boolean = false
  initDateRange: any = {
    startTime: '',
    endTime: ''
  } // 时间组件需要渲染的值
  companyData: any = {
    companyId: '',
    companyName: ''
  }
  provinceId: string = '' //省份ID
  provinceList: any = [] //省份列表数据

  auditStatus: any = '' //审核状态
  constructor(private jsonApiService: JsonApiService, private router: Router, private activatedRoute: ActivatedRoute) {
    activatedRoute.queryParams.subscribe(queryParams => {
      this.curPage = queryParams.nowPage || 1
      if (common.getCookie('jumpTo/system/car')) {
        this.jumpData = JSON.parse(common.getCookie('jumpTo/system/car'))
        this.initDateRange.startTime = this.jumpData.startTime
        this.initDateRange.endTime = this.jumpData.endTime
        this.companyData.companyId = this.selectedCompanyId = this.jumpData.companyId
        this.companyData.companyName = this.selectedCompanyName = this.jumpData.companyName
        this.searchKey = this.jumpData.deviceId
      }

      // 从信息汇总跳转过来的数据
      const summaryInfoParams = JSON.parse(common.getCookie('jumpFromSummaryInfo'))
      if (summaryInfoParams) {
        this.searchKey = summaryInfoParams.deviceId
        this.companyData.companyId = summaryInfoParams.companyId
        this.companyData.companyName = summaryInfoParams.companyName
        common.clearCookie('jumpFromSummaryInfo')
      }
    })
  }
  delhwVersion() {
    this.hwVersion = ''
  }
  // 接收子组件传递过来的数据
  getSelectTableTime(time) {
    this.startTime = time.startTime
    this.endTime = time.endTime
  }
  //公司选中回调
  companySelected(data) {
    this.selectedCompanyId = data.companyId
    this.selectedCompanyName = data.companyName
  }
  // 获取省份列表
  getProvinceList() {
    this.jsonApiService.http_get('region/getChinessProvince.html').subscribe(data => {
      if (data.success) {
        this.provinceList = data.data
      }
    })
  }
  // 获取用户类型列表
  initUserTypeList() {
    this.jsonApiService.http('role/userTypeList.html', {}).subscribe(data => {
      if (data.success) {
        for (let index = 0; index < data.data.length; index++) {
          const element = data.data[index]
          element.text = element.userTypeName
          element.id = element.userType
        }
        this.userTypeList = data.data
      }
    })
  }
  companyTeamSelected(data) {
    $('button[type="submit"]').removeAttr('disabled')
    this.outsourcingTeamId = data.companyId || ''
    this.outsourcingTeamName = data.companyName || ''
  }

  ngOnInit() {
    let that = this
    this.initBtn()
    this.modalMove()
    this.getUserList()
    this.reaustHeader() //请求表头
    this.getProvinceList() //请求省份数据
    this.initUserTypeList()
    if (this.inputParam.length == 0) {
      this.querySensor()
    } // 请求传感器列表接口
    if (common.getCookie('jumpTo/system/car')) {
      setTimeout(() => {
        that.load()
      }, 100)
      common.clearCookie('jumpTo/system/car')
    } else {
      this.load()
    }
    System.import('assets/js/viewer/viewer.js').then(() => {
      System.import('assets/js/viewer/bootstrap.bundle.min.js').then(() => {
        System.import('assets/js/viewer/viewer.css').then(() => {})
      })
    })

    const modal: HTMLElement = document.querySelector('#modal-box')
    const header = document.querySelector('#modal-header-box')
    header.addEventListener('mousedown', function (e: MouseEvent) {
      //鼠标在对话框内的坐标
      let x = e.pageX - modal.offsetLeft
      let y = e.pageY - modal.offsetTop
      // 鼠标移动时，将鼠标在对话框框中的位置赋值给对话框
      document.addEventListener('mousemove', move)
      function move(e) {
        modal.style.left = e.pageX - x + 'px'
        modal.style.top = e.pageY - y + 'px'
      }
      document.addEventListener('mouseup', function () {
        document.removeEventListener('mousemove', move)
      })
    })
    // 初始化车辆选择框
    this.initCar()
  }
  //导出
  exportData() {
    var parameters = {
      searchKey: this.searchKey,
      useTypeL1: this.useTypeL1,
      useTypeL2: this.useTypeL2,
      companyId: this.selectedCompanyId,
      startTime: this.startTime,
      endTime: this.endTime,
      sensorType: this.sensorType,
      hwVersion: this.hwVersion,
      auditStatus: this.auditStatus,
      carAttribution: this.carAttribution,
      payWay: this.payWay,
      provinceId: this.provinceId,
      userType: this.userType,
      outsourcingTeamId: this.outsourcingTeamId
    }
    let timeCheck = common.correctTime(parameters)
    if (!timeCheck.status) {
      this.jsonApiService.message(timeCheck.message)
      return
    }
    common.exprotDataFile(parameters, 'param', config.BaseURL + 'car/exportCarListFile.html')
  }
  //安装统计导出
  exprotTotalData() {
    var parameters = {
      searchKey: this.searchKey,
      useTypeL1: this.useTypeL1,
      useTypeL2: this.useTypeL2,
      companyId: this.selectedCompanyId,
      startTime: this.startTime,
      endTime: this.endTime,
      sensorType: this.sensorType,
      hwVersion: this.hwVersion,
      auditStatus: this.auditStatus,
      provinceId: this.provinceId,
      userType: this.userType,
      outsourcingTeamId: this.outsourcingTeamId
    }
    let timeCheck = common.correctTime(parameters)
    if (!timeCheck.status) {
      this.jsonApiService.message(timeCheck.message)
      return
    }
    common.exprotDataFile(parameters, 'param', config.BaseURL + 'car/exportNewCarListFile.html')
  }

  exprotMonthData() {
    const parameters = {
      startTime: this.startTime,
      endTime: this.endTime
    }
    let timeCheck = common.correctTime(parameters)
    if (!timeCheck.status) {
      this.jsonApiService.message(timeCheck.message)
      return
    }
    const url =
      config.BaseURL +
      'carStatistics/monthInstallStatisticsExport.html?startTime=' +
      this.startTime +
      '&endTime=' +
      this.endTime +
      '&allCompanyId=' +
      this.selectedCompanyId
    window.location.href = url
  }

  // 车辆安装信息导出
  exportCarInstallInfo() {
    var parameters = {
      searchKey: this.searchKey,
      useTypeL1: this.useTypeL1,
      useTypeL2: this.useTypeL2,
      companyId: this.selectedCompanyId,
      startTime: this.startTime,
      endTime: this.endTime,
      sensorType: this.sensorType,
      hwVersion: this.hwVersion,
      auditStatus: this.auditStatus,
      provinceId: this.provinceId,
      userType: this.userType,
      outsourcingTeamId: this.outsourcingTeamId
    }
    let timeCheck = common.correctTime(parameters)
    if (!timeCheck.status) {
      this.jsonApiService.message(timeCheck.message)
      return
    }
    common.exprotDataFile(parameters, 'param', config.BaseURL + 'car/exportGroupingCarListFile.html')
  }

  ngOnDestroy() {
    document.onclick = null
  }
  //table刷新
  refresh() {
    this.load()
  }
  //权限按钮
  initBtn() {
    this.btnData = JSON.parse(decodeURIComponent(localStorage.getItem('cargpsw_system:car')))
    if (!this.btnData) {
      return
    }
    for (let item of this.btnData) {
      if (item.sourceKey === 'car:add' && item.parentId) {
        this.carAdd = true
      }
      if (item.sourceKey === 'car:edit' && item.parentId) {
        this.carEdit = true
      }
      if (item.sourceKey === 'car:deleteBatch' && item.parentId) {
        this.carDeleteBatch = true
      }
      if (item.sourceKey === 'car:station' && item.parentId) {
        this.carStation = true
      }
      if (item.sourceKey === 'car:itinerary' && item.parentId) {
        this.carItinerary = true
      }
      if (item.sourceKey === 'install:img:check' && item.parentId) {
        this.imgCheck = true
      }
    }
  }
  //车辆用途change回调
  carUseTypeL1Change() {
    this.carTypeDetailList = []
    this.useTypeL2 = ''
    for (let item of this.carTypeList) {
      if (item.id === this.useTypeL1) {
        this.carTypeDetailList = item.children
        break
      }
    }
  }
  //表格搜索
  table_search() {
    this.curPage = 1
    this.searchKey = common.stringTrim(this.searchKey)
    this.load()
  }
  //初始化加载list数据
  load() {
    let timeCheck = common.correctTimeParams(this.startTime, this.endTime, 0)
    if (!timeCheck.status) {
      this.jsonApiService.message(timeCheck.message)
      return
    }
    let data = {
      pageSize: this.pageSize,
      nowPage: this.curPage,
      parameters: {
        startTime: this.startTime,
        endTime: this.endTime,
        searchKey: this.searchKey,
        useTypeL1: this.useTypeL1,
        useTypeL2: this.useTypeL2,
        companyId: this.selectedCompanyId,
        sensorType: this.sensorType,
        hwVersion: this.hwVersion,
        auditStatus: this.auditStatus,
        carAttribution: this.carAttribution,
        payWay: this.payWay,
        provinceId: this.provinceId,
        userType: this.userType,
        outsourcingTeamId: this.outsourcingTeamId
      }
    }
    let reqdata = 'gridPager=' + JSON.stringify(data)
    this.jsonApiService.http('car/list.html', reqdata).subscribe(data => {
      if (data.isSuccess) {
        for (let item of data.exhibitDatas) {
          item.useTypeL1 = this.getUseTypeNameL1(item.useTypeL1)
          item.useTypeL2 = this.getUseTypeNameL2(item.useTypeL2)
          //查询是否存在行驶证的图片
          item.isShowDrivingBtn = false
          if (item.imageInfo && item.imageInfo.length > 0) {
            item.isShowDrivingBtn = item.imageInfo.find(o => o.index === 8) ? true : false
          }
        }
        this.tableData = data.exhibitDatas
        this.totalCount = data.recordCount
      } else {
        this.jsonApiService.message(data.message)
      }
    })
  }
  getUseTypeNameL1(key) {
    if (key) {
      return this.carUseList[key]
    } else {
      return ''
    }
  }
  getUseTypeNameL2(key) {
    if (key) {
      return this.carDeatailUseList[key]
    } else {
      return ''
    }
  }
  imgInfo: any = [] //单个图片列表
  tableSelectedRow: any //存储选中row数据
  installer: string = '' //安装人
  //关闭图片弹窗
  imgClose(val) {
    this.modal.carNumber = ''
    this.modal.picture = ''
    val.hide()
    // $(".imagesInfo").find('img').viewer('destroy');
  }
  //查看照片
  open_img(row, val) {
    this.tableSelectedRow = row
    var that = this
    this.imgInfo = []
    if (this.isViewer && $('.viewer-container').length > 0) {
      this.viewer.destroy()
    }
    val.show()
    this.modal.carNumber = row.carNumber
    for (var b = 0; b < row.imageInfo.length; b++) {
      row.imageInfo[b].localImg = []
      for (let c = 0; c < row.imageInfo[b].imageList.length; c++) {
        let localImg
        if (row.imageInfo[b].imageList[c].indexOf('http') == -1) {
          if (row.imageInfo[b].imageList[c][0] == '/') {
            localImg = config.BaseURL + row.imageInfo[b].imageList[c].substr(1)
          } else {
            localImg = config.BaseURL + row.imageInfo[b].imageList[c]
          }
        } else {
          localImg = row.imageInfo[b].imageList[c]
        }
        row.imageInfo[b].localImg.push(localImg)
      }
    }
    this.jsonApiService
      .http_obj('carInstallAudit/getAuditLog.html', { deviceId: this.tableSelectedRow.deviceId })
      .subscribe(data => {
        if (data.success) {
          this.installer = ''
          let res = data.data
          for (let i = 0; i < res.length; i++) {
            if (!res[i].carInstallAuditEntities) {
              row.imageInfo[i].carInstallAuditEntities = {
                deviceId: this.tableSelectedRow.deviceId,
                carNumber: this.tableSelectedRow.carNumber,
                //                          quality: '不合格',
                qualityType: '0',
                index: res[i].index,
                describe: '',
                imageUrl: res[i].imageList
              }
            } else {
              if (!this.installer) {
                this.installer = res[i].userName
              }
              row.imageInfo[i].carInstallAuditEntities = {
                deviceId: res[i].carInstallAuditEntities.deviceId,
                carNumber: res[i].carInstallAuditEntities.carNumber,
                //                          quality: res[i].carInstallAuditEntities.quality,
                qualityType: res[i].carInstallAuditEntities.qualityType + '',
                index: res[i].carInstallAuditEntities.index,
                describe: res[i].carInstallAuditEntities.describe,
                imageUrl: res[i].carInstallAuditEntities.imageUrl
              }
            }
          }
        } else {
          for (let i = 0; i < row.imageInfo.length; i++) {
            row.imageInfo[i].carInstallAuditEntities = {
              deviceId: this.tableSelectedRow.deviceId,
              carNumber: this.tableSelectedRow.carNumber,
              //                      quality: '不合格',
              qualityType: '0',
              index: row.imageInfo[i].index,
              describe: '',
              imageUrl: row.imageInfo[i].imageList
            }
          }
        }
        this.imgInfo = row.imageInfo
      })
  }
  // 保存记录
  saveCheckRecord(item) {
    this.jsonApiService.http_obj('carInstallAudit/saveAuditLog.html', item.carInstallAuditEntities).subscribe(data => {
      this.jsonApiService.message(data.message)
      this.load()
    })
  }
  // 推送安装人
  pushCheckInfoToInstaller(item) {
    this.saveCheckRecord(item)
    item.carInstallAuditEntities.userName = this.installer
    this.jsonApiService.http_obj('carInstallAudit/pushAudit.html', item.carInstallAuditEntities).subscribe(data => {
      this.jsonApiService.message(data.message)
    })
  }
  /**
   *  推送他人模块
   */
  pushOtherInfo: any = {} // 推送他人信息
  pushCheckInfoToOther(item, modal) {
    modal.show()
    this.pushOtherInfo = item
  }
  // 推送他人
  submitUserNamePush(modal) {
    this.jsonApiService
      .http_obj('carInstallAudit/pushAudit.html', this.pushOtherInfo.carInstallAuditEntities)
      .subscribe(data => {
        this.jsonApiService.message(data.message)
      })
  }
  // 取消推送他人
  cancelUserNamePush(modal) {
    modal.hide()
  }
  userList: any
  paramFormat: any = {
    id: 'userName',
    text: 'name'
  }
  // 用户
  getUserList() {
    this.jsonApiService.http('user/getUserList.html', null).subscribe(data => {
      if (data.success) {
        this.userList = data.data
      }
    })
  }
  //角色选中
  optionSelectedForm(data) {
    this.pushOtherInfo.carInstallAuditEntities.userName = data.id
  }
  //站点管理
  site_management(row) {
    this.router.navigate(['/system/car/car-station'], {
      queryParams: {
        companyId: row.companyId,
        deviceId: row.deviceId,
        carNumber: row.carNumber,
        nowPage: this.curPage
      }
    })
  }
  //分页回调
  paginate(e) {
    this.curPage = e.page + 1
    this.pageSize = e.rows
    this.load()
  }
  //新建车辆
  new_car() {
    this.router.navigate(['/system/car/car-page'], {
      queryParams: {
        type: 'new'
      }
    })
  }
  //编辑车辆
  updata_car(row) {
    this.router.navigate(['/system/car/car-page'], {
      queryParams: {
        id: row.id,
        type: 'updata',
        nowPage: this.curPage
      }
    })
  }
  //删除车辆
  del_car(row) {
    this.jsonApiService.confirm_message('此操作将永久删除数据,确认要删除?').then(() => {
      let reqdata = 'ids=' + row.id
      this.jsonApiService.http('car/deleteBatch.html', reqdata).subscribe(data => {
        this.jsonApiService.message(data.message)
        this.load()
      })
    })
  }
  bigImgUrl: any = '' // 放大的图片
  drivingBigImg(modal, row) {
    const that = this
    if (this.isViewer && $('.viewer-container').length > 0) {
      this.viewer.destroy()
    }
    const viewerContainers: any = window.document.querySelectorAll('.viewer-container')
    for (const item of viewerContainers) {
      item.parentNode.removeChild(item)
    }

    that.bigImgUrl = row
    modal.show()
    $(window).trigger('resize')

    setTimeout(function () {
      $('.modal-imgContent').trigger('click')
      $('.modal-backdrop').css('display', 'none')
    }, 200)
  }
  //放大图片的关闭
  drivingImgClose(modal) {
    const that = this
    if (this.isViewer && $('.viewer-container').length > 0) {
      that.isViewer = false
      this.viewer.destroy()
    }
    that.bigImgUrl = ''
    modal.hide()
  }
  //图片放大
  bigImg(row, type) {
    // this.bigImgUrl = row
    if (this.isViewer && $('.viewer-container').length > 0) {
      System.import('assets/js/viewer/viewer.js').then(() => {
        System.import('assets/js/viewer/bootstrap.bundle.min.js').then(() => {
          System.import('assets/js/viewer/viewer.css').then(() => {
            this.showImg(type)
          })
        })
      })
    } else {
      this.showImg(type)
    }
  }
  CloseBigImg(modal) {
    modal.hide()
  }
  //显示图片组件
  viewer: any = ''
  showImg(type) {
    var that = this
    var imgList = $('.' + type)[0]
    let isInline = false

    if (type === 'modal-imgContent') {
      isInline = true
    } else {
      isInline = false
    }
    this.viewer = new Viewer(imgList, {
      url: 'src',
      inline: isInline,
      title: function (image) {
        return image.alt + ' (' + (this.index + 1) + '/' + this.length + ')'
      }
    })

    that.isViewer = true
  }

  /*
   *
   *    表头管理
   *
   *
   */

  faultJson: any = [
    {
      field: '操作',
      fieldName: 'operation1',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 1
    },
    {
      field: '行驶证',
      fieldName: 'driving',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 2
    },
    {
      field: '设备ID',
      fieldName: 'deviceId',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 3
    },
    {
      field: '车牌号',
      fieldName: 'carNumber',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 4
    },
    {
      field: '所属公司',
      fieldName: 'parentName',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 5
    },
    {
      field: '用途分类',
      fieldName: 'useTypeL2',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 6
    },
    {
      field: '传感器通道',
      fieldName: 'sensorChannel',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 7
    },
    {
      field: '录入人员',
      fieldName: 'userNameForCreate',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 8
    },
    {
      field: '安装时间',
      fieldName: 'inputDate',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 9
    },
    {
      field: '车辆归属',
      fieldName: 'carAttribution',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 10
    },
    {
      field: '司机电话',
      fieldName: 'phone',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 11
    },
    {
      field: '曾用车牌',
      fieldName: 'usedNumbers',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 12
    },
    {
      field: '备注',
      fieldName: 'remark',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 13
    },
    {
      field: '传感器问题',
      fieldName: 'sensorProblemList',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 14
    },
    {
      field: 'GPS问题',
      fieldName: 'gpsProblemEntity',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 15
    },
    {
      field: 'GPS天线',
      fieldName: 'gpsAntenna',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 16
    },
    {
      field: 'GSM天线',
      fieldName: 'gsmAntenna',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 17
    },
    {
      field: '硬件版本',
      fieldName: 'hwVersion',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 18
    },
    {
      field: '固件版本',
      fieldName: 'fwVersion',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 19
    },
    {
      field: '传感器类型',
      fieldName: 'sensorType',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 20
    },
    {
      field: 'SIM卡号',
      fieldName: 'sim',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 21
    },
    {
      field: 'GPS编码',
      fieldName: 'gpsId',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 22
    },
    {
      field: '车辆类型',
      fieldName: 'carType',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 23
    },
    {
      field: '用途',
      fieldName: 'useTypeL1',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 24
    },
    {
      field: '轴数',
      fieldName: 'carAxleAmount',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 25
    },
    {
      field: '传感器数量',
      fieldName: 'sensorAmount',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 26
    },
    {
      field: '荷载重量',
      fieldName: 'loadCapacity',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 27
    },
    {
      field: '单位',
      fieldName: 'unit',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 28
    },
    {
      field: '更新人',
      fieldName: 'userNameForUpdate',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 29
    },
    {
      field: '更新时间',
      fieldName: 'updateDate',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 30
    },
    {
      field: '操作',
      fieldName: 'operation',
      mark: 'system:car',
      menuName: '车辆管理',
      isHide: 0,
      order: 31
    }
  ]

  isSwitch: boolean = false //默认隐藏
  faultList: any = [] //页面jsonList
  faultPopupList: any = [] //弹窗jsonList
  //插入数据库表头
  insertHeader() {
    this.jsonApiService
      .http_obj('header/insertBatchHeader.html', { headerEntityList: JSON.stringify(this.faultJson) })
      .subscribe(data => {
        this.jsonApiService.message(data.message)
        if (data.success) {
          this.reaustHeader() //再次请求表头
        }
      })
  }
  //请求表头
  reaustHeader() {
    this.jsonApiService.http_obj('header/field.html', { mark: 'system:car' }).subscribe(data => {
      if (!data.success) {
        this.insertHeader()
      } else {
        var dataList = data.data.headerList

        for (let i = 0; i < dataList.length; i++) {
          if (dataList[i].isHide == 0) {
            dataList[i].isStatus = true
          } else {
            dataList[i].isStatus = false
          }
          dataList[i].order = i + 1
        }
        this.faultList = JSON.parse(JSON.stringify(dataList))
        this.faultPopupList = JSON.parse(JSON.stringify(dataList))
      }
    })
  }
  //初始化开关
  initSwitch() {
    var that = this
    $('.isStatus').bootstrapSwitch({
      //初始化按钮
      onText: '显示',
      offText: '隐藏',
      onColor: 'primary',
      offColor: 'warning',
      onSwitchChange: function (event, state) {
        // state 为true 隐藏  false 不隐藏
        if (state == true) {
          that.checkStatus(0, event.target.attributes.key.nodeValue)
        } else {
          that.checkStatus(1, event.target.attributes.key.nodeValue)
        }
      }
    })
  }
  setHeader(modal) {
    var that = this
    this.faultPopupList = JSON.parse(JSON.stringify(this.faultList))
    modal.show()
    System.import('assets/js/bootstrap-switch.min.js').then(() => {
      System.import('assets/css/bootstrap-switch.min.css').then(() => {
        setTimeout(function () {
          that.initSwitch()
          that.isSwitch = true
        }, 1)
      })
    })
  }
  //关闭表头弹窗
  closeHeader(modal) {
    modal.hide()
    this.isSwitch = false
  }
  //重置表头
  recoveryHeader() {
    var that = this

    this.faultPopupList = JSON.parse(JSON.stringify(this.faultList))

    System.import('assets/js/bootstrap-switch.min.js').then(() => {
      System.import('assets/css/bootstrap-switch.min.css').then(() => {
        setTimeout(function () {
          that.initSwitch()
          that.isSwitch = true
        }, 1)
      })
    })
  }
  //确定提交表头
  submitHeader(modal) {
    var mark = 'system:car'
    var field = []
    var fieldName = []
    var isShow = []
    for (var i = 0; i < this.faultPopupList.length; i++) {
      field.push(this.faultPopupList[i].field)
      fieldName.push(this.faultPopupList[i].fieldName)
      isShow.push(this.faultPopupList[i].isHide)
    }
    var reqdata = new FormData()

    reqdata.append('mark', mark)
    reqdata.append('field', field.join(','))
    reqdata.append('fieldName', fieldName.join(',')) //type 1获取相对路径  2获取绝对路径
    reqdata.append('isShow', isShow.join(','))

    this.jsonApiService.form_http('header/updateBatchHeader.html', reqdata).subscribe(data => {
      if (data.success) {
        modal.hide()
        this.isSwitch = false
        this.reaustHeader() //请求表头
        this.load()
      }
    })
  }
  //移动 type 1:上移  2：下移  3：置顶  4：置底
  MoveClick(row, type) {
    var that = this
    if (row.order == 1) {
      if (type == '1') {
        this.jsonApiService.message('已经在第一位，暂不能上移')
        return
      } else if (type == '3') {
        this.jsonApiService.message('已经在第一位，暂不能置顶')
        return
      }
    }

    if (row.order == this.faultPopupList.length) {
      if (type == '2') {
        this.jsonApiService.message('已经在最后一位，暂不能下移')
        return
      } else if (type == '4') {
        this.jsonApiService.message('已经在最后一位，暂不能置底')
        return
      }
    }

    var List = JSON.parse(JSON.stringify(this.faultPopupList))
    for (var i = 0; i < List.length; i++) {
      if (List[i].order == row.order) {
        if (type == '1') {
          List[i - 1].order = List[i - 1].order + 1
          List[i].order = row.order - 1
          break
        } else if (type == '2') {
          List[i + 1].order = List[i + 1].order - 1
          List[i].order = row.order + 1
          break
        } else if (type == '3') {
          List[i].order = 1
        } else if (type == '4') {
          List[i].order = List.length
        }
      } else {
        if (List[i].order > row.order && type == '4') {
          List[i].order = List[i].order - 1
        } else if (List[i].order < row.order && type == '3') {
          List[i].order = List[i].order + 1
        }
      }
    }

    List = List.sort(this.compare('order'))
    this.faultPopupList = JSON.parse(JSON.stringify(List))

    System.import('assets/js/bootstrap-switch.min.js').then(() => {
      System.import('assets/css/bootstrap-switch.min.css').then(() => {
        setTimeout(function () {
          that.initSwitch()
          that.isSwitch = true
        }, 1)
      })
    })
  }
  compare(property) {
    return function (a, b) {
      var value1 = a[property]
      var value2 = b[property]
      return value1 - value2
    }
  }

  //是否启用
  checkStatus(check, key) {
    var that = this
    var List = JSON.parse(JSON.stringify(this.faultPopupList))
    for (var i = 0; i < List.length; i++) {
      if (List[i].fieldName == key) {
        if (check == 1) {
          List[i].isHide = check
          List[i].isStatus = false
        } else {
          List[i].isHide = check
          List[i].isStatus = true
        }
      }
    }

    List = List.sort(this.compare('order'))
    this.faultPopupList = JSON.parse(JSON.stringify(List))

    System.import('assets/js/bootstrap-switch.min.js').then(() => {
      System.import('assets/css/bootstrap-switch.min.css').then(() => {
        setTimeout(function () {
          that.initSwitch()
          that.isSwitch = true
        }, 1)
      })
    })
  }
  //请求传感器类型的接口
  querySensor() {
    this.jsonApiService.http('sensorManage/querySensorList.html', '').subscribe(data => {
      if (data.success) {
        this.inputParam = data.data
      }
    })
  }
  inputParam: any = []
  //组件传回来 传感器类型
  sensorSelected(data) {
    this.sensorType = data.sensorType
  }
  hoverImg() {
    this.getMousePos()
  }
  getMousePos() {
    var x = 5
    var y = 15
    requestAnimationFrame(function () {
      // document.querySelectorAll(".imgCont img").forEach(ele=>{
      //     ele.addEventListener('mousemove', function(e:MouseEvent){
      //         document.getElementById("showImg").setAttribute('src', this.src);
      //         document.getElementById("showId").style.cssText+=`top: ${e.clientY + y}px; left: ${e.clientX + x}px; display: block;`
      //     })
      //     // ele.addEventListener('mouseout')
      // })
      $('.imgCont img')
        .mousemove(function (e) {
          //设置提示图片的路径
          if (!this.src) return
          $('.hover-content img').attr('src', this.src)
          $('.hover-content')
            .css({ top: e.clientY + y + 'px', left: e.clientX + x + 'px' })
            .show(200) //显示图片
        })
        .mouseout(function () {
          $('.hover-content img').attr('src', '')
          $('.hover-content').hide() //隐藏图片
        })
    })
  }

  /**
   * 行驶证识别图片
   */

  /**
   * 行驶证识别图片
   */
  carInfo: any = {
    ocrCarNumber: '', //车牌号
    carNumber: '', //外部车牌号
    deviceId: '', //设备编号
    useCharacter: '', //使用性质
    registerDate: '', //注册日期
    vehicleType: '', //车辆类型
    model: '', //品牌型号
    issuingAuthority: '', //发证机关
    name: '', //车辆所有人
    vin: '', //车辆识别代码
    issueDate: '', //发证日期
    approvedLoad: '', //核定载质量(吨)
    inspectionRecord: '', //检验有效期
    fileNo: '', //行驶证档案编号
    grossMass: '', //车辆总重量(吨)
    energyType: '', //车辆能源类型
    unladenMass: '', //整备质量(吨)
    dimensionLength: '', //外廓尺寸(长)
    dimensionWidth: '', //外廓尺寸(宽)
    dimensionHeight: '', //外廓尺寸(高)
    auditStatus: '' //审核结果
  }
  drivingImg: any = [] //行驶证图片
  carInfoId: any = '' //车辆列表主键Id
  carDeviceId: any = '' //这辆车的设备id
  carNumber: any = '' //车辆列表中的carNumber
  auditStatus1: boolean = false
  auditStatus2: boolean = false
  //打开行驶证弹窗
  open_driving(row) {
    if (this.isViewer && $('.viewer-container').length > 0) {
      this.viewer.destroy()
    }
    const viewerContainers: any = window.document.querySelectorAll('.viewer-container')
    for (const item of viewerContainers) {
      item.parentNode.removeChild(item)
    }
    if (row.imageInfo && row.imageInfo.length > 0) {
      for (let i = 0; i < row.imageInfo.length; i++) {
        if (row.imageInfo[i].index === 8) {
          this.drivingImg = row.imageInfo[i].imageList
        }
      }
    }
    this.auditStatus1 = false
    this.auditStatus2 = false

    this.carInfoId = row.id
    this.carDeviceId = row.deviceId
    this.carNumber = row.carNumber
    //回显审核结果
    if (row.auditStatus === 1) {
      this.auditStatus1 = true
      this.auditStatus2 = false
    } else if (row.auditStatus === 2) {
      this.auditStatus1 = false
      this.auditStatus2 = true
    }
    this.seeCarInfo(row.id)
    this.initCarDate()
    // modal.show()
    $('#deviceDrivingModal').show()
  }

  //设备详细弹窗注册拖动事件
  modalMove() {
    var that = this
    $('body').undelegate('#headDrag', 'mousedown', function () {})
    $('body').delegate('#headDrag', 'mousedown', function (e) {
      $(this).css('cursor', 'move')
      var offset = $('#deviceDrivingModal').position()
      var x = e.pageX - offset.left
      var y = e.pageY - offset.top
      $(document).bind('mousemove', function (ev) {
        $('#deviceDrivingModal').stop()
        var _x = ev.pageX - x
        var _y = ev.pageY - y
        if (_y < 0) {
          //避开头部横条
          return
        }
        $('#deviceDrivingModal').animate(
          {
            left: _x + 'px',
            top: _y + 'px'
          },
          2
        )
      })
    })
    $(document).mouseup(function (e) {
      e.cancelBubble = true
      $(this).unbind('mousemove')
    })
    $('body').undelegate('#dragArrow', 'mousedown', function () {})
    $('body').delegate('#dragArrow', 'mousedown', function (e) {
      let ele = $('#deviceDrivingModal')
      let x = e.pageX - ele.width()
      $('body').bind('mousemove', function (ev) {
        $('#deviceDrivingModal').stop()
        let _x = ev.pageX - x
        if (_x < 1200) {
          //避开头部横条
          return
        }
        $('#deviceDrivingModal')
          .find('.modal-dialog')
          .animate(
            {
              width: _x + 'px'
            },
            2
          )
        //				setTimeout(()=>{
        let W = $('#popContent').width() - 2

        $('#echartBox').width(W * 0.55 * 0.65 - 1)
        $('#allmapBox').width(W * 0.55 * 0.35)
        $('#chart').width(W * 0.55 * 0.65 - 1)
        $(window).trigger('resize')
        //				},120)
      })
    })

    $('body').mouseup(function (e) {
      e.cancelBubble = true
      $(this).unbind('mousemove')
      //			$(window).trigger('resize');
    })
  }

  //查看识别出来的数据
  seeCarInfo(id) {
    this.jsonApiService.http_get('carDrivingLicense/queryCarDrivingLicenseByCarId.html?carId=' + id).subscribe(data => {
      if (data.success) {
        for (let item in data.data) {
          this.carInfo[item] = data.data[item]
        }
      } else {
        for (let item in this.carInfo) {
          this.carInfo[item] = ''
        }
      }
    })
  }
  //选中审核
  changeAuditStatus(type) {
    this.carInfo.auditStatus = type
    this.auditStatus1 = type === 1 ? true : false
    this.auditStatus2 = type === 2 ? true : false
  }
  initCarDate() {
    const that = this
    System.import('assets/js/datepicker/js/bootstrap-datetimepicker.min.js').then(() => {
      System.import('assets/js/datepicker/locales/bootstrap-datetimepicker.zh-CN.js').then(() => {
        $('#registerDate')
          .datetimepicker({
            //时间插件
            format: 'yyyy-mm-dd',
            language: 'zh-CN',
            autoclose: true,
            minView: 2
          })
          .on('changeDate', function (e) {
            var date = e.date
            if (!date) {
              return
            }
            var time = common.getTimeDay(date)
            that.carInfo.registerDate = time
          })
        $('#issueDate')
          .datetimepicker({
            //时间插件
            format: 'yyyy-mm-dd',
            language: 'zh-CN',
            autoclose: true,
            minView: 2
          })
          .on('changeDate', function (e) {
            var date = e.date
            if (!date) {
              return
            }
            var time = common.getTimeDay(date)
            that.carInfo.issueDate = time
          })
        $('#inspectionRecord')
          .datetimepicker({
            //时间插件
            format: 'yyyy-mm',
            language: 'zh-CN',
            autoclose: true,
            startView: 3,
            minView: 3
          })
          .on('changeDate', function (e) {
            var date = e.date
            if (!date) {
              return
            }
            var time = common.getTimeDay(date)
            that.carInfo.inspectionRecord = time.substring(0, time.length - 3)
          })
      })
    })
  }
  //通过图片地址识别信息
  distinguishImg(img, value) {
    const that = this
    var reqdata = new FormData()
    reqdata.append('path', img)
    reqdata.append('type', value)
    this.jsonApiService.form_http('carDrivingLicense/queryCarDrivingLicenseForOCR.html', reqdata).subscribe(data => {
      this.jsonApiService.message(data.message)
      if (data.success) {
        for (let item in data.data) {
          if (data.data[item]) {
            that.carInfo[item] = data.data[item]
            // //处理发证日期和注册日期
            // if (item == 'registerDate') {
            // 	that.carInfo.registerDate = that.handleDate(data.data[item])
            // }
            // if (item == 'issueDate') {
            // 	that.carInfo.issueDate = that.handleDate(data.data[item])
            // }
            // //处理检验有效期
            // if (item == 'inspectionRecord') {
            // 	that.carInfo.inspectionRecord = that.handleRecord(data.data[item])
            // }
            // //处理外廊尺寸
            // if (item == 'dimension') {
            // 	let dimension = that.handleDimension(data.data[item])
            // 	that.carInfo.dimensionLength = dimension[0]
            // 	that.carInfo.dimensionWidth = dimension[1]
            // 	that.carInfo.dimensionHeight = dimension[2]
            // }
            // //处理吨以及千克换算
            // if (item == 'grossMass' || item == 'unladenMass' || item == 'approvedLoad') {
            // 	that.carInfo[item] = that.handleConversion(data.data[item])
            // }
          }
        }
        if (that.carInfo.dimensionLength == null) {
          that.carInfo.dimensionLength = ''
        }
        if (that.carInfo.dimensionWidth == null) {
          that.carInfo.dimensionWidth = ''
        }
        if (that.carInfo.dimensionHeight == null) {
          that.carInfo.dimensionHeight = ''
        }
      }
    })
  }
  //处理识别出来的数据 检验有效期
  handleRecord(value) {
    let month = value.split('月')[0]
    let year = value.split('年')[0]
    const receiveDate = year.substring(year.length - 4) + '-' + month.substring(month.length - 2)
    return receiveDate
  }
  //处理识别出来的数据 外廓尺寸
  handleDimension(data) {
    let dimensionValue = data.replace('mm', '').replace('毫米', '')
    let dimensionText: any
    if (dimensionValue.indexOf('×') != -1) {
      dimensionText = dimensionValue.split('×')
    } else if (dimensionValue.indexOf('*') != -1) {
      dimensionText = dimensionValue.split('*')
    } else if (dimensionValue.indexOf('X') != -1) {
      dimensionText = dimensionValue.split('X')
    } else {
      return
    }
    return dimensionText
  }
  //处理识别出来的数据 注册日期和发证日期
  handleDate(data) {
    let result
    result = data.substring(0, 4) + '-' + data.substring(4, 6) + '-' + data.substring(6, 8)
    return result
  }
  //处理识别出来的数据 吨和千克的换算
  handleConversion(data) {
    let result
    result = data.indexOf('kg') != -1 ? data.replace('kg', '') : data
    return result
  }
  drivingClose() {
    $('#deviceDrivingModal').hide()
  }
  //提交车辆信息
  submitDriving() {
    let data = Object.assign({}, this.carInfo)
    data.deviceId = this.carDeviceId
    data.carNumber = this.carNumber
    data.carInfoId = this.carInfoId
    var reqdata = new FormData()
    if (data.dimensionLength == '' || data.dimensionLength == null) {
      delete data.dimensionLength
    }
    if (data.dimensionWidth == '' || data.dimensionWidth == null) {
      delete data.dimensionWidth
    }
    if (data.dimensionHeight == '' || data.dimensionHeight == null) {
      delete data.dimensionHeight
    }
    for (let item in data) {
      if (data[item] == null) {
        reqdata.append(item, '')
      } else {
        reqdata.append(item, data[item])
      }
    }
    this.jsonApiService
      .form_http('carDrivingLicense/saveOrUpdateCarDrivingLicenseByCarId.html', reqdata)
      .subscribe(data => {
        this.jsonApiService.message(data.message)
        if (data.success) {
          this.load()
          // modal.hide()
          $('#deviceDrivingModal').hide()
        }
      })
  }

  numberForm = { id: '', deviceId: '', companyId: '', oldCarNumber: '', carNumber: '', remark: '', imageList: [] }
  dockingTableData: any[] = [] // 车辆对接信息

  validatorOptions = {
    excluded: [':disabled'],
    feedbackIcons: {
      valid: 'glyphicon glyphicon-ok',
      invalid: 'glyphicon glyphicon-remove',
      validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
      id: {
        validators: {
          notEmpty: {
            message: '请选择车辆'
          }
        }
      },
      carNumber: {
        validators: {
          notEmpty: {
            message: '请输入新车牌号码'
          }
        }
      },
      imageList: {
        validators: {
          notEmpty: {
            message: '请上传车辆正面图片'
          }
        }
      }
    }
  }

  //初始化车辆
  initCar() {
    var self = this
    $('#carNumberSelect2')
      .select2({
        language: 'zh-CN',
        minimumInputLength: 4,
        allowClear: true,
        placeholder: '请选择',
        ajax: {
          url: config.BaseURL + 'stats/carListByCarNumber.html',
          dataType: 'json',
          delay: 50,
          method: 'POST',
          xhrFields: { withCredentials: true },
          data: function (params) {
            return { carNumber: params.term }
          },
          processResults: function (data, params) {
            const options = []
            // 小于10个数量才判断重复
            if (data.data.length <= 10) {
              let arr = []
              let sameCar = []
              // 判断相同的车牌号
              for (let index = 0; index < data.data.length; index++) {
                let car = data.data[index]
                if (arr.indexOf(car.carNumber) != -1) {
                  sameCar.push(car.carNumber) //重复车辆
                } else {
                  arr.push(car.carNumber)
                }
              }
              $(data.data).each(function (index, car) {
                const option = {
                  id: car.id,
                  companyId: car.companyId,
                  value: car.deviceId,
                  text: car.carNumber,
                  imageInfo: car.imageInfo,
                  remark: car.remark
                }
                if (sameCar.indexOf(car.carNumber) != -1) {
                  // 重复车辆，选项添加 【car.parentName】
                  option.text = car.carNumber + '[' + car.parentName + ']'
                }
                options.push(option)
              })
            } else {
              $(data.data).each(function (index, car) {
                options.push({
                  id: car.id,
                  companyId: car.companyId,
                  value: car.deviceId,
                  text: car.carNumber,
                  imageInfo: car.imageInfo,
                  remark: car.remark,
                })
              })
            }
            return {
              results: options //获取查询后的结果
            }
          },
          cache: true
        },
        templateResult: function (state) {
          if (!state.id) {
            return state.text
          }
          var $state = $('<span><i class="fa fa-car green"></i>&nbsp;&nbsp;' + state.text + '</span>')
          return $state
        }
      })
      .on('select2:select', function (e) {
        var data = e.params.data
        self.numberForm.id = data.id
        self.numberForm.companyId = data.companyId
        self.numberForm.deviceId = data.value
        self.numberForm.remark = data.remark
        if (data.text.indexOf('[') > 0) {
          self.numberForm.oldCarNumber = data.text.split('[')[0]
        } else {
          self.numberForm.oldCarNumber = data.text
        }
        if (data.imageInfo && data.imageInfo.length > 0) {
          self.numberForm.imageList = data.imageInfo.filter(item => item.index === 1)[0]
            ? data.imageInfo.filter(item => item.index === 1)[0].imageList
            : []
        } else {
          self.numberForm.imageList = []
        }
        self.fetchDockingData({ deviceId: self.numberForm.deviceId })
      })
  }

  fetchDockingData(data) {
    this.jsonApiService.http_obj('projectCar/queryProjectCarInfoByDeviceId.html', data).subscribe(data => {
      if (data.success) {
        this.dockingTableData = data.data
      } else {
        this.dockingTableData = []
      }
    })
  }

  handleEditNumber(modal) {
    modal.show()
  }

  //上传多张
  multifileChange(files: FileList) {
    if (this.isViewer && $('.viewer-container').length > 0) {
      this.viewer.destroy()
    }

    const that = this
    const multfileList = files

    var reqdata = new FormData()
    reqdata.append('describe', '车辆正面')
    reqdata.append('businessType', '1')
    reqdata.append('type', '2') //type 1获取相对路径  2获取绝对路径

    for (var i = 0; i < multfileList.length; i++) {
      const fileList = multfileList[i]
      const isJPG =
        fileList.type === 'image/jpeg' || fileList.type === 'image/jpg' || fileList.type === 'image/png'
      if (!isJPG) {
        this.jsonApiService.message('上传图片只能是 png, jpg, jpeg 格式!')
        return
      }

      reqdata.append('files', multfileList[i])
    }

    that.jsonApiService.form_http('fileUpload/upload.html', reqdata).subscribe(data => {
      if (data.success) {
        for (var i = 0; i < data.data.length; i++) {
          that.numberForm.imageList.push(data.data[i])
        }
      }
    })

    for (let k = 0; k < $('.up').length; k++) {
      $('.up')[k].value = null
    }
  }
  //删除
  deleteImg(i) {
    this.numberForm.imageList.splice(i, 1)

    if (this.isViewer && $('.viewer-container').length > 0) {
      this.viewer.destroy()
    }
  }

  closeEditNumberModal(modal) {
    $('#carNumberSelect2').val(null).trigger('change') // 清空车辆选择
    $('#editNumberForm').data('bootstrapValidator').resetForm() // 重置校验信息
    this.numberForm = {
      id: '',
      deviceId: '',
      companyId: '',
      oldCarNumber: '',
      carNumber: '',
      imageList: [],
      remark: ''
    }
    this.dockingTableData = []
    // notice 提交后要清空选项，select2 会在选中后创建 option
    // 下次选择有缓存，可能和服务器返回数据不一致
    // https://select2.org/data-sources/ajax
    $('#carNumberSelect2').html("<option value=''></option>")
    modal.hide()
  }

  // 编辑车辆提交
  onNumberEditSubmit(modal) {
    $('#editNumberForm').bootstrapValidator('validate') //开启验证
    const isValid = $('#editNumberForm').data('bootstrapValidator').isValid() //验证是否通过
    if (!isValid) {
      return
    }
    if(this.numberForm.imageList.length === 0){
      this.jsonApiService.message('请上传车辆正面图片')
      return
    }
    this.verifyAlikeCar(() => {
      this.editNumberCommit(modal)
    })
  }

  // 验证项目已存在相同车牌号码
  verifyAlikeCar(cb) {
    let params = {
      id: this.numberForm.id,
      companyId: this.numberForm.companyId,
      carNumber: this.numberForm.carNumber
    }
    this.jsonApiService.http_obj('car/checkCarNumberByCompany.html', params).subscribe(data => {
      if (!data.success && data.message) {
        this.jsonApiService.confirm_message(data.message).then(() => {
          cb()
        })
      } else {
        cb()
      }
    })
  }

  editNumberCommit(modal) {
    const data = { ...this.numberForm, imageListJsonForType1: '' }
    data.imageListJsonForType1 = JSON.stringify(data.imageList)
    delete data.imageList
    delete data.deviceId
    delete data.oldCarNumber
    delete data.companyId
    const reqdata = new FormData()
    for (let item in data) {
      if (data[item] == null) {
        reqdata.append(item, '')
      } else {
        reqdata.append(item, data[item])
      }
    }
    this.jsonApiService.form_http('car/editCarNumber.html', reqdata).subscribe(res => {
      this.jsonApiService.message(res.message)
      if (res.success) {
        this.load()
        this.closeEditNumberModal(modal)
      }
    })
  }

  handleBlock() {
    if (!this.numberForm.oldCarNumber) {
      this.jsonApiService.message('请选择车牌')
      return
    }
    if (this.numberForm.oldCarNumber.includes('-停用')) {
      // ElMessage.error('车辆已标记停用')
      this.numberForm.carNumber = this.numberForm.oldCarNumber
      return
    }
    this.numberForm.carNumber = this.numberForm.oldCarNumber + '-停用'
  }
}
